#!/bin/bash

# ===============================================
#    F U N C T I O N S   D E F I N I T I O N S
# ===============================================
# -----------------------------------------------
# Definition : KILL_PROCESS
# -----------------------------------------------
function kill_process() {

    local process=$1
    pid_file="/tmp/pids.$RANDOM"
    ps -C $process -o pid > $pid_file
    cat $pid_file
    echo $process
    exec 3<&0
    exec 0<$pid_file
    while read pid
    do
	if [ ! $? -eq 1 ] ; then
	    echo $pid
	    kill $pid
	fi   
    done
    exec 0<&3
    
    rm $pid_file
    
}



# ===============================================
#      S C R I P T   M A I N   E N T R Y
# ===============================================

# We shouldn't have any arguments
if [ $# -ne 1 ] ; then
    	echo "Usage: $0 <process_name>"
	exit 1
fi


# -----------------------------------------------
# Start testing
# -----------------------------------------------
kill_process $1
